<template>
  <div v-loading="loading" :element-loading-text="loadingText" class="audit">
    <div class="bread-box but20">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item class="btn-green" style=" color: #3DC094;" @click.native="clickBack">环境成品配置</el-breadcrumb-item>
        <el-breadcrumb-item>环境成品配置单</el-breadcrumb-item>
        <el-breadcrumb-item>审核</el-breadcrumb-item>
      </el-breadcrumb>
      <div>
        <el-button size="mini" @click="clickBack">取消</el-button>
        <el-button type="primary" @click="confirmHandle">确认</el-button>
      </div>
    </div>
    <div style="margin-top: 20px;">
      <el-form ref="form" :model="formData" :rules="formRules" label-width="80px">
        <el-form-item prop="reviewResult" label="审核结果" :rules="[{ required: true, message: '请选择审核结果' }]">
          <el-select v-model="formData.reviewResult" placeholder="审核结果" @change="resultChange">
            <el-option value="1" label="同意" />
            <el-option value="0" label="不同意" />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="reviewAdvice"
          label="审核意见"
          :rules="[{ required: formData.reviewResult === '0', message: '请输入审核意见' }]"
        >
          <el-input v-model="formData.reviewAdvice" type="textarea" :autosize="{minRows:3}" maxlength="1024" placeholder="审核意见" />
        </el-form-item>
      </el-form>
    </div>
    <Detail is-audit />
  </div>
</template>
<script>
import Detail from './detail'
import { getProConfigEditData, auditConfigEditData } from '@/api/proConfig'
export default {
  name: 'Audit',
  components: {
    Detail
  },
  data() {
    return {
      loading: false,
      loadingText: '',
      type: '',
      proStateList: [],
      canBePurchaseList: [],
      designRangeList: [],
      decorationTypeList: [],
      designSpaceList: [],
      designBizTypeList: [],
      formData: {},
      tableConfig: {
        setting: [
          {
            prop: 'picTaskCode',
            label: '图纸编码',
            minWidth: 100
          },
          {
            prop: 'picType',
            label: '图纸类型',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'PIC_TYPE'
            },
            minWidth: 100
          },
          {
            prop: 'designRange',
            label: '设计范围',
            minWidth: 100,
            render: (creat, row) => {
              if (!row.designRange) {
                return
              }
              let list = []
              if (typeof (row.designRange) === 'string') {
                list = row.designRange.split(',')
              } else {
                list = row.designRange
              }
              const arr = []
              this.designRangeList.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'decorationType',
            label: '装修形式',
            minWidth: 100,
            render: (creat, row) => {
              if (!row.decorationType) {
                return
              }
              let list = []
              if (typeof (row.decorationType) === 'string') {
                list = row.decorationType.split(',')
              } else {
                list = row.decorationType
              }
              const arr = []
              this.decorationTypeList.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'designSpace',
            label: '设计专区',
            minWidth: 100,
            render: (creat, row) => {
              if (!row.designSpace) {
                return
              }
              let list = []
              if (typeof (row.designSpace) === 'string') {
                list = row.designSpace.split(',')
              } else {
                list = row.designSpace
              }
              const arr = []
              this.designSpaceList.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'designBizType',
            label: '设计业务类型',
            minWidth: 140,
            render: (creat, row) => {
              if (!row.designBizType) {
                return
              }
              let list = []
              if (typeof (row.designBizType) === 'string') {
                list = row.designBizType.split(',')
              } else {
                list = row.designBizType
              }
              const arr = []
              this.designBizTypeList.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'picTotalArea',
            label: '设计总面积',
            minWidth: 120
          },
          {
            prop: 'endProArea',
            label: '成品面积',
            minWidth: 100
          },
          {
            prop: 'haveEAndC',
            label: '是否含成融定',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            },
            minWidth: 140
          },
          {
            prop: 'finishedProductAreaSummary',
            label: '成融定面积',
            minWidth: 120
          },
          {
            prop: 'allCustomizedArea',
            label: '定制面积',
            minWidth: 100
          },
          {
            prop: 'overCupboardArea',
            label: '橱柜面积',
            minWidth: 100
          },
          {
            prop: 'bathroomArea',
            label: '卫浴面积',
            minWidth: 100
          },
          {
            prop: 'modelRoomArea',
            label: '样板间面积',
            minWidth: 100
          },
          {
            prop: 'expectEndTime',
            label: '预计设计完成时间',
            minWidth: 140
          },
          {
            prop: 'designUnitName',
            label: '设计单位',
            minWidth: 100
          },
          {
            prop: 'designerName',
            label: '设计师',
            minWidth: 100
          },
          {
            prop: 'schedule',
            label: '图纸进度',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'PIC_DESIGN_SCHEDULE'
            },
            minWidth: 100
          },
          {
            prop: 'state',
            label: '图纸状态',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'PIC_DESIGN_STATE'
            },
            minWidth: 100
          }
        ]
      }
      // formData: {
      //   result: '',
      //   reviewAdvice: ''
      // },
      // formRules: {
      //   result: [{ required: true, message: '请选择审核结果', trigger: 'change' }],
      //   reviewAdvice: [{ required: false, message: '请填写审核意见', trigger: 'change' }]
      // }
    }
  },
  async created() {
    this.loading = true
    this.loadingText = '加载中'
    this.formData.id = this.$route.params.id
    this.type = this.$route.params.type
    getProConfigEditData(this.formData.id).then(res => {
      if (res.success && res.data) {
        this.formData = res.data
        this.$set(this.formData, 'reviewAdvice', '')
        this.$set(this.formData, 'reviewResult', '')
        this.$nextTick(() => {
          this.$refs.form.clearValidate()
        })
      }
      this.loading = false
    }).catch(() => {
      this.loading = false
    })
  },
  methods: {
    // // 选择审核结果
    // resultChange(v) {
    //   const fb = this.formRules.reviewAdvice[0]
    //   if (v === '0') {
    //     this.$set(fb, 'required', true)
    //   } else {
    //     this.$set(fb, 'required', false)
    //   }
    //   this.$refs.form.clearValidate('reviewAdvice')
    // },
    confirmHandle() {
      this.$refs.form.validate(validate => {
        if (validate) {
          this.loading = true
          this.loadingText = '系统处理中'
          if (this.formData.reviewResult === '1') {
            this.formData.schedule = 'C'
          } else {
            this.formData.schedule = 'A'
          }
          auditConfigEditData(this.formData).then(res => {
            if (res.success) {
              this.$message.success('操作成功')
              this.clickBack()
            }
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    clickBack() {
      this.$store.dispatch('views/goBack')
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
